<%-- 
    Document   : FSolicitation
    Created on : 02/05/2010, 16:16:55
s--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="br.terminalrodoviario.Solicitation"%>
<%@page import="br.terminalrodoviario.Company"%>
<%@page import="java.util.*, java.text.*" %>
<jsp:useBean class="br.terminalrodoviario.Solicitation" id="Solicitation" scope="page"/>

<%
            String id = request.getParameter("id");
            if (id != null) {
                Solicitation = new Solicitation().selectById("Select n from Solicitation n where n.id = " + id);
            }
%>

<jsp:useBean class="br.terminalrodoviario.User" id="user" scope="session"/>
<%
        if (user.getId() == 0) {
            response.sendRedirect("../login.jsp");
        }
%>

<script type="text/javascript">
    function verifyFields(){
        var cboCompany = document.getElementById("cboCompany");
        var txtDateSolicitation = document.getElementById("txtDateSolicitation");
        var txtDateResolution = document.getElementById("txtDateResolution");
        document.getElementById('validate').innerHTML = '';
        document.getElementById('validate1').innerHTML = '';
        document.getElementById('validate2').innerHTML = '';
        var fill = true;

        var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
        if (!((txtDateSolicitation.value.match(expReg)) && (txtDateSolicitation.value!=''))) {
            document.getElementById('validate1').innerHTML = 'Formato inválido de data';
            fill=false;
            txtDateSolicitation.focus();
        }
        if (!((txtDateResolution.value.match(expReg)) && (txtDateResolution.value!=''))) {
            document.getElementById('validate2').innerHTML = 'Formato inválido de data';
            fill=false;
            txtDateResolution.focus();
        }

        if(cboCompany.value=="" || cboCompany.value == null){
            document.getElementById('validate').innerHTML = 'Selecione a empresa';
            fill=false;
        }
        if(txtDateSolicitation.value==""){
            document.getElementById('validate1').innerHTML = 'Informe a data';
            fill=false;
        }
        if(txtDateResolution.value==""){
            document.getElementById('validate2').innerHTML = 'Informe a data';
            fill=false;
        }
        if(fill==false)
            return;
        document.getElementById("form").submit();
    }

</script>
<html>
    <head>
        <title>Guia Terminal Rodoviário</title>
        <%SimpleDateFormat formatBra = new SimpleDateFormat("dd/MM/yyyy");%>
        <style type="text/css">
            @import url("../../add/css/cssAdmin.css");
            @import url("../../add/css/rodape.css");
        </style>
    </head>
    <body>
        <div class="geral">
            <table>
                <tr>
                    <td>
                        <div id="cabecalho">
                        </div>
                    </td>
                </tr>
            </table>
            <table id="menuAdmin" width="762">
                <tr >
                    <td>
                        <ul class="menuCidade" >
                            <li><a href="../Manager/MCity.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuEmpresa" >
                            <li><a href="../Manager/MCompany.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuTerminais" >
                            <li><a href="../Manager/MBusStation.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuHoteis" >
                            <li><a href="../Manager/MHotel.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuNoticias" >
                            <li><a href="../Manager/MNotice.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuSolicitacao" >
                            <li class="current"><a href="../Manager/MSolicitation.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuDicas" >
                            <li><a href="../Manager/MTravelTip.jsp" /></li>
                        </ul>
                    </td>

                </tr>
            </table>

            <div style="float:left">
                <br/>
                <b><a href="../index.jsp">Início</a> -> <a href="../Manager/MSolicitation.jsp">Solicitações</a> -> <a href="FSolicitation.jsp">Cadastrar Solicitação</a></b>
                <br/><br/>
            </div>
            <div align="right" style="font-family:calibri; font-size:11px; font-style:inherit">
                <br/>Bem-vindo <b><%=request.getSession().getAttribute("username")%></b>,<br/>
                você está logado desde <%=request.getSession().getAttribute("date_session")%>h. ( <a href="../logout.jsp"><b>Logout</b></a> )<br/><br/>
            </div>

            <table  id="subTitulo">
                <tr>
                    <td id="icone">
                        &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../add/images/icones/solicitation.png" alt="Solicitações" title="Solicitações"/>
                    </td>
                    <td>
                        Solicitação
                    </td>
                </tr>
            </table>
            <br>

            <form id="form" action="../SolicitationServlet?acao=gravar&id=<%=request.getParameter("id")%>" method="post">
                <div align="right"><b style="color:red">(*) campos obrigatórios</b></div>
                <table cellpadding="0" cellspacing="0">
                    <tr>
                        <td class="label_bg" style="width:150px;">&nbsp;&nbsp;Empresa:</td>
                        <td>&nbsp;
                            <select id="cboCompany" name="cboCompany" style="width:450px; height:22px;">
                                <% for (Company c : new Company().select("from Company c where c.removed=0")) {%>
                                <option value="<%=c.getId()%>" <%=(Solicitation.getCompany() != null && Solicitation.getCompany().getId() == c.getId() ? "selected='true'" : "")%>><%=c.getName()%></option>
                                <%}%>
                            </select>
                            <b style="color:red">*</b> <b id="validate"></b>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">&nbsp;&nbsp;Data da solicitação:</td>
                        <td>&nbsp;&nbsp;<input type="text" id="txtDateSolicitation" name="txtDateSolicitation" value="<%=Solicitation.getDateSolicitation() == null ? formatBra.format(new java.util.Date()) : formatBra.format(Solicitation.getDateSolicitation())%>" size="40"> <b style="color:red">*</b> <b id="validate1"></b></td>
                    </tr>
                    <tr>
                        <td class="label_bg" style="width:150px;">&nbsp;&nbsp;Data da resolução:</td>
                        <td>&nbsp;&nbsp;<input type="text" id="txtDateResolution" name="txtDateResolution" value="<%=Solicitation.getDateResolution() == null ? formatBra.format(new java.util.Date()) : formatBra.format(Solicitation.getDateResolution())%>" size="40"> <b id="validate2"></b></td>
                    </tr>
                    <tr>
                        <td class="label" valign="top">&nbsp;&nbsp;Descrição:</td>
                        <td>&nbsp;&nbsp;<textarea name="txtDescription" rows="7" cols="35" style="width:444px">
                                <%=Solicitation.getDescription() == null ? "" : Solicitation.getDescription()%>
                            </textarea>
                        </td>
                    </tr>
                </table>
                <table>
                    <tr>
                        <td align="right" colspan="2" width="605"><input type="button" onclick="javascript:verifyFields();" align="right" value="Gravar" name="enviar"><br></td>
                    </tr>
                </table>
            </form>
        </div>
        <br>
        <table id="rodape" style="background-image:url(../../add/images/rodape.png);">
            <tr>
            </tr>
        </table>
        <table id="btRodape" style="text-decoration: none;" >
            <tr>
                <td align="center" width="80px">
                    <ul class="btYoutube">
                        <li><a title="Youtube" href="http://www.youtube.com" /></li>
                    </ul>
                </td >
                <td align="center" width="80px">
                    <ul class="btOrkut">
                        <li><a title="Orkut" href="http://www.orkut.com" /></li>
                    </ul>
                </td>
                <td align="center" width="205px">
                    <ul class="btTwitter">
                        <li><a title="Twitter" href="http://twitter.com" /></li>
                    </ul>
                </td>
                <td align="center">
                    <a title="Trabalhe Conosco" class="text" href="../../Carrer.jsp" >Trabalhe Conosco</a>
                </td>
                <td align="center"  width="">
                    <a title="Mapa do Site" class="text" href="../../SiteMap.jsp">Mapa do Site</a>
                </td>
                <td align="center" width="">
                    <a title="Contatos" class="text" href="../../Contact.jsp">Contatos</a>
                </td>
            </tr>
        </table>
    </body>
</html>

